home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / source.test < prev    next >
Encoding:
Text File  |  1995-03-29  |  3.5 KB  |  121 lines

  1. # Commands covered:  source
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) source.test 1.10 95/03/29 11:24:42
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test source-1.1 {source command} {
  18.     set x "old x value"
  19.     set y "old y value"
  20.     set z "old z value"
  21.     exec cat << {
  22.     set x 22
  23.     set y 33
  24.     set z 44
  25.     } > source.file
  26.     source source.file
  27.     list $x $y $z
  28. } {22 33 44}
  29. test source-1.2 {source command} {
  30.     exec cat << {list result} > source.file
  31.     source source.file
  32. } result
  33.  
  34. test source-2.1 {source error conditions} {
  35.     list [catch {source} msg] $msg
  36. } {1 {wrong # args: should be "source fileName"}}
  37. test source-2.2 {source error conditions} {
  38.     list [catch {source a b} msg] $msg
  39. } {1 {wrong # args: should be "source fileName"}}
  40. test source-2.3 {source error conditions} {
  41.     exec cat << {
  42.     set x 146
  43.     error "error in sourced file"
  44.     set y $x
  45.     } > source.file
  46.     list [catch {source source.file} msg] $msg $errorInfo
  47. } {1 {error in sourced file} {error in sourced file
  48.     while executing
  49. "error "error in sourced file""
  50.     (file "source.file" line 3)
  51.     invoked from within
  52. "source source.file"}}
  53. test source-2.4 {source error conditions} {
  54.     exec cat << {break} > source.file
  55.     catch {source source.file}
  56. } 3
  57. test source-2.5 {source error conditions} {
  58.     exec cat << {continue} > source.file
  59.     catch {source source.file}
  60. } 4
  61. test source-2.6 {source error conditions} {
  62.     string tolower [list [catch {source _non_existent_} msg] $msg $errorCode]
  63. } {1 {couldn't read file "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
  64.  
  65. test source-3.1 {return in middle of source file} {
  66.     exec cat << {
  67.     set x new-x
  68.     return allDone
  69.     set y new-y
  70.     } > source.file
  71.     set x old-x
  72.     set y old-y
  73.     set z [source source.file]
  74.     list $x $y $z
  75. } {new-x old-y allDone}
  76. test source-3.2 {return with special code etc.} {
  77.     exec cat << {
  78.     set x new-x
  79.     return -code break "Silly result"
  80.     set y new-y
  81.     } > source.file
  82.     list [catch {source source.file} msg] $msg
  83. } {3 {Silly result}}
  84. test source-3.3 {return with special code etc.} {
  85.     exec cat << {
  86.     set x new-x
  87.     return -code error "Simulated error"
  88.     set y new-y
  89.     } > source.file
  90.     list [catch {source source.file} msg] $msg $errorInfo $errorCode
  91. } {1 {Simulated error} {Simulated error
  92.     while executing
  93. "source source.file"} NONE}
  94. test source-3.4 {return with special code etc.} {
  95.     exec cat << {
  96.     set x new-x
  97.     return -code error -errorinfo "Simulated errorInfo stuff"
  98.     set y new-y
  99.     } > source.file
  100.     list [catch {source source.file} msg] $msg $errorInfo $errorCode
  101. } {1 {} {Simulated errorInfo stuff
  102.     invoked from within
  103. "source source.file"} NONE}
  104. test source-3.5 {return with special code etc.} {
  105.     exec cat << {
  106.     set x new-x
  107.     return -code error -errorinfo "Simulated errorInfo stuff" \
  108.         -errorcode {a b c}
  109.     set y new-y
  110.     } > source.file
  111.     list [catch {source source.file} msg] $msg $errorInfo $errorCode
  112. } {1 {} {Simulated errorInfo stuff
  113.     invoked from within
  114. "source source.file"} {a b c}}
  115.  
  116. catch {exec rm source.file}
  117.  
  118. # Generate null final value
  119.  
  120. concat {}
  121.